package com.base.weeks.weekof59th;

/**
 * @ClassName MinTimeToType
 * @Description 5834. 使用特殊打字机键入单词的最少时间
 * @Author li
 * Date 2021/8/22 10:25
 * Copyright
 **/
public class MinTimeToType {
    public int minTimeToType(String s) {
        // 提取键入时间
        int sum = s.length();
        // 初始点在a
        char cur = 'a';
        for (int i = 0; i < s.length(); i++) {
            sum += Math.min((s.charAt(i) - cur + 26) % 26, (cur - s.charAt(i) + 26) % 26);
            cur = s.charAt(i);
        }
        return sum;
    }
}
